package com.yueqian.Dao;

import com.yueqian.Utils.JDBCUtils;

import java.sql.*;

public class LoginMapper {
    private String userName;
    private String passWord;

    public LoginMapper(String username, String password) {
        this.userName = username;
        this.passWord = password;
    }

    /**
     * 数据库判断是否存在
     * @return
     */
    public Boolean login()   {
        try {
            Connection connection = JDBCUtils.Connection();
            String sql = "select * from employee where  username = ? and password = ?";
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1, userName);
            preparedStatement.setString(2, passWord);
            ResultSet resultSet = preparedStatement.executeQuery();
            if(resultSet.next()) {
                return true;
            }
            else{
                System.out.println("用户不存在");
                return false;
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

    }

}
